<?php
	class Default_Model_News extends Zend_Db_Table_Abstract
	{
		protected $_name = 'news';
		protected $_primary = 'id';
		protected $_db;
		
		public function __construct()
		{
			$this->_db = Zend_Registry::get('db');
		}
        
        public function listItem()
        {
            $data = array(
                'id',
                'title',
                'image',
                'short_description',
                'create_date',
                'url',
            );
            $sql = $this->_db->select()
                            ->from($this->_name, $data)
                            ->where('status = 1')
                            ->order('create_date DESC');
            return $sql;
        }
        
        public function getItem($id)
        {
            $data = array(
                'title',
                'description',
                'create_date',
            );
            $sql = $this->_db->select()
                            ->from($this->_name, $data)
                            ->where('id = ?', $id)
                            ->where('status = 1');
            $result = $this->_db->fetchRow($sql);
            return $result;
        }
        
        public function getListItemById($id)
        {
            $data = array(
                'id',
                'title',
                'url',
            );
            $sql = $this->_db->select()
                            ->from($this->_name, $data)
                            ->where('id <> ?', $id)
                            ->where('status = 1')
                            ->order('create_date DESC')
                            ->limit(5);
            $result = $this->_db->fetchAll($sql);
            return $result;
        }
    }
